package com.br.facto;

import java.util.ArrayList;

import com.br.consumir.CWSAeroporto;
import com.br.consumir.CWSCompanhia;

import android.widget.AdapterView.OnItemSelectedListener;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;

public class CPesVooByCompania extends Activity implements OnClickListener,OnItemSelectedListener
{
    
    private CWSAeroporto wsAreporto;
  
    
    private Spinner spinner;
	private ArrayAdapter<String> arrayAdapter;
	
	
	
	private String sAeroporto;
	private String sCompania;
	
	private Button btEnter;
    //contrundo activity
    /****************************************************
     * 
     */
    public void onCreate(Bundle b)
    {
	super.onCreate(b);
	
	//chmando metodo que monta spinner aerporto
	
	montaSpinnerAeroporto();
	
    }

    /****************************************************/
    
    
    /****************************************************
     * Metodo monta spinner
     */
    public void montaSpinnerAeroporto()
    {
	setContentView(R.layout.busaerocia);
	//montando spinner de aeroportos
    	spinner = (Spinner)findViewById(R.id.spaeroporto);
    	spinner.setOnItemSelectedListener(this);
	wsAreporto = new CWSAeroporto();
    	//recebendo arraylista de string com aeroportos
    	ArrayList<String> sArrayAero = wsAreporto.retornaAeroportos();
    	
    	arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, sArrayAero);
    	arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
    	
    	spinner.setAdapter(arrayAdapter);
    	
    	btEnter = (Button)findViewById(R.id.btlocalizar);
    	btEnter.setOnClickListener(this);
    }
    /****************************************************/
    
    
    
    
    
    
    /*******************************************************
     * Tratando eventos
     */
    
	public void onClick(View v) 
	{
		if(v.getId() == R.id.btlocalizar)
		{
		   Intent in = new Intent(this,CPesqeCompani.class);
		   //in.putExtra("aero", this.sAeroporto);
		   Bundle parans = new Bundle();
		   parans.putString("aero", sAeroporto);
		   in.putExtras(parans);
		   startActivity(in);
		   
		}
		
	}

	public void onItemSelected(AdapterView<?> parent, View arg1, int posicao,
			long arg3) 
	{
	    this.sAeroporto = parent.getItemAtPosition(posicao).toString();
	 
	}

	public void onNothingSelected(AdapterView<?> arg0) {
	
		
	}
	/*********************************************************/
}
